package com.jml.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class ChanelApiGetChanel {

	public static void main(String[] args) throws Exception {
		FileInputStream fis = new FileInputStream("1.jpg");
		FileOutputStream fos = new FileOutputStream("2.jpg");
		//分配通道
		FileChannel fisChannel = fis.getChannel();
		FileChannel fosChannel = fos.getChannel();
		//分配指定大小缓冲区
		ByteBuffer allocate = ByteBuffer.allocate(1024);
		//将通道的数据存入缓冲区
		while(fisChannel.read(allocate)!=-1){
			//将缓冲区的数据在写入通道
			allocate.flip();
			fosChannel.write(allocate);
			Buffer clear = allocate.clear();
		}
		fisChannel.close();
		fosChannel.close();
		fis.close();
		fos.close();
	}

}
